
_wc:     file format elf32-i386


Disassembly of section .text:

00000000 <wc>:

char buf[512];

void
wc(int fd, char *name)
{
       0:	55                   	push   %ebp
       1:	89 e5                	mov    %esp,%ebp
       3:	83 ec 48             	sub    $0x48,%esp
  int i, n;
  int l, w, c, inword;

  l = w = c = 0;
       6:	c7 45 e8 00 00 00 00 	movl   $0x0,-0x18(%ebp)
       d:	8b 45 e8             	mov    -0x18(%ebp),%eax
      10:	89 45 ec             	mov    %eax,-0x14(%ebp)
      13:	8b 45 ec             	mov    -0x14(%ebp),%eax
      16:	89 45 f0             	mov    %eax,-0x10(%ebp)
  inword = 0;
      19:	c7 45 e4 00 00 00 00 	movl   $0x0,-0x1c(%ebp)
  while((n = read(fd, buf, sizeof(buf))) > 0){
      20:	eb 68                	jmp    8a <wc+0x8a>
    for(i=0; i<n; i++){
      22:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
      29:	eb 57                	jmp    82 <wc+0x82>
      c++;
      2b:	83 45 e8 01          	addl   $0x1,-0x18(%ebp)
      if(buf[i] == '\n')
      2f:	8b 45 f4             	mov    -0xc(%ebp),%eax
      32:	05 20 15 00 00       	add    $0x1520,%eax
      37:	0f b6 00             	movzbl (%eax),%eax
      3a:	3c 0a                	cmp    $0xa,%al
      3c:	75 04                	jne    42 <wc+0x42>
        l++;
      3e:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
      if(strchr(" \r\t\n\v", buf[i]))
      42:	8b 45 f4             	mov    -0xc(%ebp),%eax
      45:	05 20 15 00 00       	add    $0x1520,%eax
      4a:	0f b6 00             	movzbl (%eax),%eax
      4d:	0f be c0             	movsbl %al,%eax
      50:	89 44 24 04          	mov    %eax,0x4(%esp)
      54:	c7 04 24 32 10 00 00 	movl   $0x1032,(%esp)
      5b:	e8 61 02 00 00       	call   2c1 <strchr>
      60:	85 c0                	test   %eax,%eax
      62:	74 09                	je     6d <wc+0x6d>
        inword = 0;
      64:	c7 45 e4 00 00 00 00 	movl   $0x0,-0x1c(%ebp)
      6b:	eb 11                	jmp    7e <wc+0x7e>
      else if(!inword){
      6d:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
      71:	75 0b                	jne    7e <wc+0x7e>
        w++;
      73:	83 45 ec 01          	addl   $0x1,-0x14(%ebp)
        inword = 1;
      77:	c7 45 e4 01 00 00 00 	movl   $0x1,-0x1c(%ebp)
  int l, w, c, inword;

  l = w = c = 0;
  inword = 0;
  while((n = read(fd, buf, sizeof(buf))) > 0){
    for(i=0; i<n; i++){
      7e:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
      82:	8b 45 f4             	mov    -0xc(%ebp),%eax
      85:	3b 45 e0             	cmp    -0x20(%ebp),%eax
      88:	7c a1                	jl     2b <wc+0x2b>
  int i, n;
  int l, w, c, inword;

  l = w = c = 0;
  inword = 0;
  while((n = read(fd, buf, sizeof(buf))) > 0){
      8a:	c7 44 24 08 00 02 00 	movl   $0x200,0x8(%esp)
      91:	00 
      92:	c7 44 24 04 20 15 00 	movl   $0x1520,0x4(%esp)
      99:	00 
      9a:	8b 45 08             	mov    0x8(%ebp),%eax
      9d:	89 04 24             	mov    %eax,(%esp)
      a0:	e8 b7 03 00 00       	call   45c <read>
      a5:	89 45 e0             	mov    %eax,-0x20(%ebp)
      a8:	83 7d e0 00          	cmpl   $0x0,-0x20(%ebp)
      ac:	0f 8f 70 ff ff ff    	jg     22 <wc+0x22>
        w++;
        inword = 1;
      }
    }
  }
  if(n < 0){
      b2:	83 7d e0 00          	cmpl   $0x0,-0x20(%ebp)
      b6:	79 19                	jns    d1 <wc+0xd1>
    printf(1, "wc: read error\n");
      b8:	c7 44 24 04 38 10 00 	movl   $0x1038,0x4(%esp)
      bf:	00 
      c0:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
      c7:	e8 15 05 00 00       	call   5e1 <printf>
    exit();
      cc:	e8 73 03 00 00       	call   444 <exit>
  }
  printf(1, "%d %d %d %s\n", l, w, c, name);
      d1:	8b 45 0c             	mov    0xc(%ebp),%eax
      d4:	89 44 24 14          	mov    %eax,0x14(%esp)
      d8:	8b 45 e8             	mov    -0x18(%ebp),%eax
      db:	89 44 24 10          	mov    %eax,0x10(%esp)
      df:	8b 45 ec             	mov    -0x14(%ebp),%eax
      e2:	89 44 24 0c          	mov    %eax,0xc(%esp)
      e6:	8b 45 f0             	mov    -0x10(%ebp),%eax
      e9:	89 44 24 08          	mov    %eax,0x8(%esp)
      ed:	c7 44 24 04 48 10 00 	movl   $0x1048,0x4(%esp)
      f4:	00 
      f5:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
      fc:	e8 e0 04 00 00       	call   5e1 <printf>
}
     101:	c9                   	leave  
     102:	c3                   	ret    

00000103 <main>:

int
main(int argc, char *argv[])
{
     103:	55                   	push   %ebp
     104:	89 e5                	mov    %esp,%ebp
     106:	83 e4 f0             	and    $0xfffffff0,%esp
     109:	83 ec 20             	sub    $0x20,%esp
  int fd, i;

  if(argc <= 1){
     10c:	83 7d 08 01          	cmpl   $0x1,0x8(%ebp)
     110:	7f 19                	jg     12b <main+0x28>
    wc(0, "");
     112:	c7 44 24 04 55 10 00 	movl   $0x1055,0x4(%esp)
     119:	00 
     11a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     121:	e8 da fe ff ff       	call   0 <wc>
    exit();
     126:	e8 19 03 00 00       	call   444 <exit>
  }

  for(i = 1; i < argc; i++){
     12b:	c7 44 24 1c 01 00 00 	movl   $0x1,0x1c(%esp)
     132:	00 
     133:	e9 8f 00 00 00       	jmp    1c7 <main+0xc4>
    if((fd = open(argv[i], 0)) < 0){
     138:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     13c:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
     143:	8b 45 0c             	mov    0xc(%ebp),%eax
     146:	01 d0                	add    %edx,%eax
     148:	8b 00                	mov    (%eax),%eax
     14a:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     151:	00 
     152:	89 04 24             	mov    %eax,(%esp)
     155:	e8 2a 03 00 00       	call   484 <open>
     15a:	89 44 24 18          	mov    %eax,0x18(%esp)
     15e:	83 7c 24 18 00       	cmpl   $0x0,0x18(%esp)
     163:	79 2f                	jns    194 <main+0x91>
      printf(1, "cat: cannot open %s\n", argv[i]);
     165:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     169:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
     170:	8b 45 0c             	mov    0xc(%ebp),%eax
     173:	01 d0                	add    %edx,%eax
     175:	8b 00                	mov    (%eax),%eax
     177:	89 44 24 08          	mov    %eax,0x8(%esp)
     17b:	c7 44 24 04 56 10 00 	movl   $0x1056,0x4(%esp)
     182:	00 
     183:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     18a:	e8 52 04 00 00       	call   5e1 <printf>
      exit();
     18f:	e8 b0 02 00 00       	call   444 <exit>
    }
    wc(fd, argv[i]);
     194:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     198:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
     19f:	8b 45 0c             	mov    0xc(%ebp),%eax
     1a2:	01 d0                	add    %edx,%eax
     1a4:	8b 00                	mov    (%eax),%eax
     1a6:	89 44 24 04          	mov    %eax,0x4(%esp)
     1aa:	8b 44 24 18          	mov    0x18(%esp),%eax
     1ae:	89 04 24             	mov    %eax,(%esp)
     1b1:	e8 4a fe ff ff       	call   0 <wc>
    close(fd);
     1b6:	8b 44 24 18          	mov    0x18(%esp),%eax
     1ba:	89 04 24             	mov    %eax,(%esp)
     1bd:	e8 aa 02 00 00       	call   46c <close>
  if(argc <= 1){
    wc(0, "");
    exit();
  }

  for(i = 1; i < argc; i++){
     1c2:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
     1c7:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     1cb:	3b 45 08             	cmp    0x8(%ebp),%eax
     1ce:	0f 8c 64 ff ff ff    	jl     138 <main+0x35>
      exit();
    }
    wc(fd, argv[i]);
    close(fd);
  }
  exit();
     1d4:	e8 6b 02 00 00       	call   444 <exit>
     1d9:	66 90                	xchg   %ax,%ax
     1db:	90                   	nop

000001dc <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
     1dc:	55                   	push   %ebp
     1dd:	89 e5                	mov    %esp,%ebp
     1df:	57                   	push   %edi
     1e0:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
     1e1:	8b 4d 08             	mov    0x8(%ebp),%ecx
     1e4:	8b 55 10             	mov    0x10(%ebp),%edx
     1e7:	8b 45 0c             	mov    0xc(%ebp),%eax
     1ea:	89 cb                	mov    %ecx,%ebx
     1ec:	89 df                	mov    %ebx,%edi
     1ee:	89 d1                	mov    %edx,%ecx
     1f0:	fc                   	cld    
     1f1:	f3 aa                	rep stos %al,%es:(%edi)
     1f3:	89 ca                	mov    %ecx,%edx
     1f5:	89 fb                	mov    %edi,%ebx
     1f7:	89 5d 08             	mov    %ebx,0x8(%ebp)
     1fa:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
     1fd:	5b                   	pop    %ebx
     1fe:	5f                   	pop    %edi
     1ff:	5d                   	pop    %ebp
     200:	c3                   	ret    

00000201 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
     201:	55                   	push   %ebp
     202:	89 e5                	mov    %esp,%ebp
     204:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
     207:	8b 45 08             	mov    0x8(%ebp),%eax
     20a:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
     20d:	90                   	nop
     20e:	8b 45 0c             	mov    0xc(%ebp),%eax
     211:	0f b6 10             	movzbl (%eax),%edx
     214:	8b 45 08             	mov    0x8(%ebp),%eax
     217:	88 10                	mov    %dl,(%eax)
     219:	8b 45 08             	mov    0x8(%ebp),%eax
     21c:	0f b6 00             	movzbl (%eax),%eax
     21f:	84 c0                	test   %al,%al
     221:	0f 95 c0             	setne  %al
     224:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     228:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
     22c:	84 c0                	test   %al,%al
     22e:	75 de                	jne    20e <strcpy+0xd>
    ;
  return os;
     230:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     233:	c9                   	leave  
     234:	c3                   	ret    

00000235 <strcmp>:

int
strcmp(const char *p, const char *q)
{
     235:	55                   	push   %ebp
     236:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
     238:	eb 08                	jmp    242 <strcmp+0xd>
    p++, q++;
     23a:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     23e:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
     242:	8b 45 08             	mov    0x8(%ebp),%eax
     245:	0f b6 00             	movzbl (%eax),%eax
     248:	84 c0                	test   %al,%al
     24a:	74 10                	je     25c <strcmp+0x27>
     24c:	8b 45 08             	mov    0x8(%ebp),%eax
     24f:	0f b6 10             	movzbl (%eax),%edx
     252:	8b 45 0c             	mov    0xc(%ebp),%eax
     255:	0f b6 00             	movzbl (%eax),%eax
     258:	38 c2                	cmp    %al,%dl
     25a:	74 de                	je     23a <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
     25c:	8b 45 08             	mov    0x8(%ebp),%eax
     25f:	0f b6 00             	movzbl (%eax),%eax
     262:	0f b6 d0             	movzbl %al,%edx
     265:	8b 45 0c             	mov    0xc(%ebp),%eax
     268:	0f b6 00             	movzbl (%eax),%eax
     26b:	0f b6 c0             	movzbl %al,%eax
     26e:	89 d1                	mov    %edx,%ecx
     270:	29 c1                	sub    %eax,%ecx
     272:	89 c8                	mov    %ecx,%eax
}
     274:	5d                   	pop    %ebp
     275:	c3                   	ret    

00000276 <strlen>:

uint
strlen(char *s)
{
     276:	55                   	push   %ebp
     277:	89 e5                	mov    %esp,%ebp
     279:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
     27c:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     283:	eb 04                	jmp    289 <strlen+0x13>
     285:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     289:	8b 55 fc             	mov    -0x4(%ebp),%edx
     28c:	8b 45 08             	mov    0x8(%ebp),%eax
     28f:	01 d0                	add    %edx,%eax
     291:	0f b6 00             	movzbl (%eax),%eax
     294:	84 c0                	test   %al,%al
     296:	75 ed                	jne    285 <strlen+0xf>
    ;
  return n;
     298:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     29b:	c9                   	leave  
     29c:	c3                   	ret    

0000029d <memset>:

void*
memset(void *dst, int c, uint n)
{
     29d:	55                   	push   %ebp
     29e:	89 e5                	mov    %esp,%ebp
     2a0:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
     2a3:	8b 45 10             	mov    0x10(%ebp),%eax
     2a6:	89 44 24 08          	mov    %eax,0x8(%esp)
     2aa:	8b 45 0c             	mov    0xc(%ebp),%eax
     2ad:	89 44 24 04          	mov    %eax,0x4(%esp)
     2b1:	8b 45 08             	mov    0x8(%ebp),%eax
     2b4:	89 04 24             	mov    %eax,(%esp)
     2b7:	e8 20 ff ff ff       	call   1dc <stosb>
  return dst;
     2bc:	8b 45 08             	mov    0x8(%ebp),%eax
}
     2bf:	c9                   	leave  
     2c0:	c3                   	ret    

000002c1 <strchr>:

char*
strchr(const char *s, char c)
{
     2c1:	55                   	push   %ebp
     2c2:	89 e5                	mov    %esp,%ebp
     2c4:	83 ec 04             	sub    $0x4,%esp
     2c7:	8b 45 0c             	mov    0xc(%ebp),%eax
     2ca:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
     2cd:	eb 14                	jmp    2e3 <strchr+0x22>
    if(*s == c)
     2cf:	8b 45 08             	mov    0x8(%ebp),%eax
     2d2:	0f b6 00             	movzbl (%eax),%eax
     2d5:	3a 45 fc             	cmp    -0x4(%ebp),%al
     2d8:	75 05                	jne    2df <strchr+0x1e>
      return (char*)s;
     2da:	8b 45 08             	mov    0x8(%ebp),%eax
     2dd:	eb 13                	jmp    2f2 <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
     2df:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     2e3:	8b 45 08             	mov    0x8(%ebp),%eax
     2e6:	0f b6 00             	movzbl (%eax),%eax
     2e9:	84 c0                	test   %al,%al
     2eb:	75 e2                	jne    2cf <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
     2ed:	b8 00 00 00 00       	mov    $0x0,%eax
}
     2f2:	c9                   	leave  
     2f3:	c3                   	ret    

000002f4 <gets>:

char*
gets(char *buf, int max)
{
     2f4:	55                   	push   %ebp
     2f5:	89 e5                	mov    %esp,%ebp
     2f7:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     2fa:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     301:	eb 46                	jmp    349 <gets+0x55>
    cc = read(0, &c, 1);
     303:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     30a:	00 
     30b:	8d 45 ef             	lea    -0x11(%ebp),%eax
     30e:	89 44 24 04          	mov    %eax,0x4(%esp)
     312:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     319:	e8 3e 01 00 00       	call   45c <read>
     31e:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
     321:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     325:	7e 2f                	jle    356 <gets+0x62>
      break;
    buf[i++] = c;
     327:	8b 55 f4             	mov    -0xc(%ebp),%edx
     32a:	8b 45 08             	mov    0x8(%ebp),%eax
     32d:	01 c2                	add    %eax,%edx
     32f:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     333:	88 02                	mov    %al,(%edx)
     335:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
     339:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     33d:	3c 0a                	cmp    $0xa,%al
     33f:	74 16                	je     357 <gets+0x63>
     341:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     345:	3c 0d                	cmp    $0xd,%al
     347:	74 0e                	je     357 <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     349:	8b 45 f4             	mov    -0xc(%ebp),%eax
     34c:	83 c0 01             	add    $0x1,%eax
     34f:	3b 45 0c             	cmp    0xc(%ebp),%eax
     352:	7c af                	jl     303 <gets+0xf>
     354:	eb 01                	jmp    357 <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
     356:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
     357:	8b 55 f4             	mov    -0xc(%ebp),%edx
     35a:	8b 45 08             	mov    0x8(%ebp),%eax
     35d:	01 d0                	add    %edx,%eax
     35f:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
     362:	8b 45 08             	mov    0x8(%ebp),%eax
}
     365:	c9                   	leave  
     366:	c3                   	ret    

00000367 <stat>:

int
stat(char *n, struct stat *st)
{
     367:	55                   	push   %ebp
     368:	89 e5                	mov    %esp,%ebp
     36a:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
     36d:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     374:	00 
     375:	8b 45 08             	mov    0x8(%ebp),%eax
     378:	89 04 24             	mov    %eax,(%esp)
     37b:	e8 04 01 00 00       	call   484 <open>
     380:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
     383:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     387:	79 07                	jns    390 <stat+0x29>
    return -1;
     389:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
     38e:	eb 23                	jmp    3b3 <stat+0x4c>
  r = fstat(fd, st);
     390:	8b 45 0c             	mov    0xc(%ebp),%eax
     393:	89 44 24 04          	mov    %eax,0x4(%esp)
     397:	8b 45 f4             	mov    -0xc(%ebp),%eax
     39a:	89 04 24             	mov    %eax,(%esp)
     39d:	e8 fa 00 00 00       	call   49c <fstat>
     3a2:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
     3a5:	8b 45 f4             	mov    -0xc(%ebp),%eax
     3a8:	89 04 24             	mov    %eax,(%esp)
     3ab:	e8 bc 00 00 00       	call   46c <close>
  return r;
     3b0:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
     3b3:	c9                   	leave  
     3b4:	c3                   	ret    

000003b5 <atoi>:

int
atoi(const char *s)
{
     3b5:	55                   	push   %ebp
     3b6:	89 e5                	mov    %esp,%ebp
     3b8:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
     3bb:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
     3c2:	eb 23                	jmp    3e7 <atoi+0x32>
    n = n*10 + *s++ - '0';
     3c4:	8b 55 fc             	mov    -0x4(%ebp),%edx
     3c7:	89 d0                	mov    %edx,%eax
     3c9:	c1 e0 02             	shl    $0x2,%eax
     3cc:	01 d0                	add    %edx,%eax
     3ce:	01 c0                	add    %eax,%eax
     3d0:	89 c2                	mov    %eax,%edx
     3d2:	8b 45 08             	mov    0x8(%ebp),%eax
     3d5:	0f b6 00             	movzbl (%eax),%eax
     3d8:	0f be c0             	movsbl %al,%eax
     3db:	01 d0                	add    %edx,%eax
     3dd:	83 e8 30             	sub    $0x30,%eax
     3e0:	89 45 fc             	mov    %eax,-0x4(%ebp)
     3e3:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
     3e7:	8b 45 08             	mov    0x8(%ebp),%eax
     3ea:	0f b6 00             	movzbl (%eax),%eax
     3ed:	3c 2f                	cmp    $0x2f,%al
     3ef:	7e 0a                	jle    3fb <atoi+0x46>
     3f1:	8b 45 08             	mov    0x8(%ebp),%eax
     3f4:	0f b6 00             	movzbl (%eax),%eax
     3f7:	3c 39                	cmp    $0x39,%al
     3f9:	7e c9                	jle    3c4 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
     3fb:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     3fe:	c9                   	leave  
     3ff:	c3                   	ret    

00000400 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
     400:	55                   	push   %ebp
     401:	89 e5                	mov    %esp,%ebp
     403:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
     406:	8b 45 08             	mov    0x8(%ebp),%eax
     409:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
     40c:	8b 45 0c             	mov    0xc(%ebp),%eax
     40f:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
     412:	eb 13                	jmp    427 <memmove+0x27>
    *dst++ = *src++;
     414:	8b 45 f8             	mov    -0x8(%ebp),%eax
     417:	0f b6 10             	movzbl (%eax),%edx
     41a:	8b 45 fc             	mov    -0x4(%ebp),%eax
     41d:	88 10                	mov    %dl,(%eax)
     41f:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     423:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
     427:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
     42b:	0f 9f c0             	setg   %al
     42e:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
     432:	84 c0                	test   %al,%al
     434:	75 de                	jne    414 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
     436:	8b 45 08             	mov    0x8(%ebp),%eax
}
     439:	c9                   	leave  
     43a:	c3                   	ret    
     43b:	90                   	nop

0000043c <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
     43c:	b8 01 00 00 00       	mov    $0x1,%eax
     441:	cd 40                	int    $0x40
     443:	c3                   	ret    

00000444 <exit>:
SYSCALL(exit)
     444:	b8 02 00 00 00       	mov    $0x2,%eax
     449:	cd 40                	int    $0x40
     44b:	c3                   	ret    

0000044c <wait>:
SYSCALL(wait)
     44c:	b8 03 00 00 00       	mov    $0x3,%eax
     451:	cd 40                	int    $0x40
     453:	c3                   	ret    

00000454 <pipe>:
SYSCALL(pipe)
     454:	b8 04 00 00 00       	mov    $0x4,%eax
     459:	cd 40                	int    $0x40
     45b:	c3                   	ret    

0000045c <read>:
SYSCALL(read)
     45c:	b8 05 00 00 00       	mov    $0x5,%eax
     461:	cd 40                	int    $0x40
     463:	c3                   	ret    

00000464 <write>:
SYSCALL(write)
     464:	b8 10 00 00 00       	mov    $0x10,%eax
     469:	cd 40                	int    $0x40
     46b:	c3                   	ret    

0000046c <close>:
SYSCALL(close)
     46c:	b8 15 00 00 00       	mov    $0x15,%eax
     471:	cd 40                	int    $0x40
     473:	c3                   	ret    

00000474 <kill>:
SYSCALL(kill)
     474:	b8 06 00 00 00       	mov    $0x6,%eax
     479:	cd 40                	int    $0x40
     47b:	c3                   	ret    

0000047c <exec>:
SYSCALL(exec)
     47c:	b8 07 00 00 00       	mov    $0x7,%eax
     481:	cd 40                	int    $0x40
     483:	c3                   	ret    

00000484 <open>:
SYSCALL(open)
     484:	b8 0f 00 00 00       	mov    $0xf,%eax
     489:	cd 40                	int    $0x40
     48b:	c3                   	ret    

0000048c <mknod>:
SYSCALL(mknod)
     48c:	b8 11 00 00 00       	mov    $0x11,%eax
     491:	cd 40                	int    $0x40
     493:	c3                   	ret    

00000494 <unlink>:
SYSCALL(unlink)
     494:	b8 12 00 00 00       	mov    $0x12,%eax
     499:	cd 40                	int    $0x40
     49b:	c3                   	ret    

0000049c <fstat>:
SYSCALL(fstat)
     49c:	b8 08 00 00 00       	mov    $0x8,%eax
     4a1:	cd 40                	int    $0x40
     4a3:	c3                   	ret    

000004a4 <link>:
SYSCALL(link)
     4a4:	b8 13 00 00 00       	mov    $0x13,%eax
     4a9:	cd 40                	int    $0x40
     4ab:	c3                   	ret    

000004ac <mkdir>:
SYSCALL(mkdir)
     4ac:	b8 14 00 00 00       	mov    $0x14,%eax
     4b1:	cd 40                	int    $0x40
     4b3:	c3                   	ret    

000004b4 <chdir>:
SYSCALL(chdir)
     4b4:	b8 09 00 00 00       	mov    $0x9,%eax
     4b9:	cd 40                	int    $0x40
     4bb:	c3                   	ret    

000004bc <dup>:
SYSCALL(dup)
     4bc:	b8 0a 00 00 00       	mov    $0xa,%eax
     4c1:	cd 40                	int    $0x40
     4c3:	c3                   	ret    

000004c4 <getpid>:
SYSCALL(getpid)
     4c4:	b8 0b 00 00 00       	mov    $0xb,%eax
     4c9:	cd 40                	int    $0x40
     4cb:	c3                   	ret    

000004cc <sbrk>:
SYSCALL(sbrk)
     4cc:	b8 0c 00 00 00       	mov    $0xc,%eax
     4d1:	cd 40                	int    $0x40
     4d3:	c3                   	ret    

000004d4 <sleep>:
SYSCALL(sleep)
     4d4:	b8 0d 00 00 00       	mov    $0xd,%eax
     4d9:	cd 40                	int    $0x40
     4db:	c3                   	ret    

000004dc <uptime>:
SYSCALL(uptime)
     4dc:	b8 0e 00 00 00       	mov    $0xe,%eax
     4e1:	cd 40                	int    $0x40
     4e3:	c3                   	ret    

000004e4 <signal>:

//our addition
SYSCALL(signal)
     4e4:	b8 1f 00 00 00       	mov    $0x1f,%eax
     4e9:	cd 40                	int    $0x40
     4eb:	c3                   	ret    

000004ec <sigsend>:
SYSCALL(sigsend)
     4ec:	b8 20 00 00 00       	mov    $0x20,%eax
     4f1:	cd 40                	int    $0x40
     4f3:	c3                   	ret    

000004f4 <alarm>:
SYSCALL(alarm)
     4f4:	b8 21 00 00 00       	mov    $0x21,%eax
     4f9:	cd 40                	int    $0x40
     4fb:	c3                   	ret    

000004fc <getTicks>:
SYSCALL(getTicks)
     4fc:	b8 22 00 00 00       	mov    $0x22,%eax
     501:	cd 40                	int    $0x40
     503:	c3                   	ret    

00000504 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
     504:	55                   	push   %ebp
     505:	89 e5                	mov    %esp,%ebp
     507:	83 ec 28             	sub    $0x28,%esp
     50a:	8b 45 0c             	mov    0xc(%ebp),%eax
     50d:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
     510:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     517:	00 
     518:	8d 45 f4             	lea    -0xc(%ebp),%eax
     51b:	89 44 24 04          	mov    %eax,0x4(%esp)
     51f:	8b 45 08             	mov    0x8(%ebp),%eax
     522:	89 04 24             	mov    %eax,(%esp)
     525:	e8 3a ff ff ff       	call   464 <write>
}
     52a:	c9                   	leave  
     52b:	c3                   	ret    

0000052c <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
     52c:	55                   	push   %ebp
     52d:	89 e5                	mov    %esp,%ebp
     52f:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
     532:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
     539:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
     53d:	74 17                	je     556 <printint+0x2a>
     53f:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
     543:	79 11                	jns    556 <printint+0x2a>
    neg = 1;
     545:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
     54c:	8b 45 0c             	mov    0xc(%ebp),%eax
     54f:	f7 d8                	neg    %eax
     551:	89 45 ec             	mov    %eax,-0x14(%ebp)
     554:	eb 06                	jmp    55c <printint+0x30>
  } else {
    x = xx;
     556:	8b 45 0c             	mov    0xc(%ebp),%eax
     559:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
     55c:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
     563:	8b 4d 10             	mov    0x10(%ebp),%ecx
     566:	8b 45 ec             	mov    -0x14(%ebp),%eax
     569:	ba 00 00 00 00       	mov    $0x0,%edx
     56e:	f7 f1                	div    %ecx
     570:	89 d0                	mov    %edx,%eax
     572:	0f b6 80 e8 14 00 00 	movzbl 0x14e8(%eax),%eax
     579:	8d 4d dc             	lea    -0x24(%ebp),%ecx
     57c:	8b 55 f4             	mov    -0xc(%ebp),%edx
     57f:	01 ca                	add    %ecx,%edx
     581:	88 02                	mov    %al,(%edx)
     583:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
     587:	8b 55 10             	mov    0x10(%ebp),%edx
     58a:	89 55 d4             	mov    %edx,-0x2c(%ebp)
     58d:	8b 45 ec             	mov    -0x14(%ebp),%eax
     590:	ba 00 00 00 00       	mov    $0x0,%edx
     595:	f7 75 d4             	divl   -0x2c(%ebp)
     598:	89 45 ec             	mov    %eax,-0x14(%ebp)
     59b:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     59f:	75 c2                	jne    563 <printint+0x37>
  if(neg)
     5a1:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     5a5:	74 2e                	je     5d5 <printint+0xa9>
    buf[i++] = '-';
     5a7:	8d 55 dc             	lea    -0x24(%ebp),%edx
     5aa:	8b 45 f4             	mov    -0xc(%ebp),%eax
     5ad:	01 d0                	add    %edx,%eax
     5af:	c6 00 2d             	movb   $0x2d,(%eax)
     5b2:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
     5b6:	eb 1d                	jmp    5d5 <printint+0xa9>
    putc(fd, buf[i]);
     5b8:	8d 55 dc             	lea    -0x24(%ebp),%edx
     5bb:	8b 45 f4             	mov    -0xc(%ebp),%eax
     5be:	01 d0                	add    %edx,%eax
     5c0:	0f b6 00             	movzbl (%eax),%eax
     5c3:	0f be c0             	movsbl %al,%eax
     5c6:	89 44 24 04          	mov    %eax,0x4(%esp)
     5ca:	8b 45 08             	mov    0x8(%ebp),%eax
     5cd:	89 04 24             	mov    %eax,(%esp)
     5d0:	e8 2f ff ff ff       	call   504 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
     5d5:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
     5d9:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     5dd:	79 d9                	jns    5b8 <printint+0x8c>
    putc(fd, buf[i]);
}
     5df:	c9                   	leave  
     5e0:	c3                   	ret    

000005e1 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
     5e1:	55                   	push   %ebp
     5e2:	89 e5                	mov    %esp,%ebp
     5e4:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
     5e7:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
     5ee:	8d 45 0c             	lea    0xc(%ebp),%eax
     5f1:	83 c0 04             	add    $0x4,%eax
     5f4:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
     5f7:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
     5fe:	e9 7d 01 00 00       	jmp    780 <printf+0x19f>
    c = fmt[i] & 0xff;
     603:	8b 55 0c             	mov    0xc(%ebp),%edx
     606:	8b 45 f0             	mov    -0x10(%ebp),%eax
     609:	01 d0                	add    %edx,%eax
     60b:	0f b6 00             	movzbl (%eax),%eax
     60e:	0f be c0             	movsbl %al,%eax
     611:	25 ff 00 00 00       	and    $0xff,%eax
     616:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
     619:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     61d:	75 2c                	jne    64b <printf+0x6a>
      if(c == '%'){
     61f:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     623:	75 0c                	jne    631 <printf+0x50>
        state = '%';
     625:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
     62c:	e9 4b 01 00 00       	jmp    77c <printf+0x19b>
      } else {
        putc(fd, c);
     631:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     634:	0f be c0             	movsbl %al,%eax
     637:	89 44 24 04          	mov    %eax,0x4(%esp)
     63b:	8b 45 08             	mov    0x8(%ebp),%eax
     63e:	89 04 24             	mov    %eax,(%esp)
     641:	e8 be fe ff ff       	call   504 <putc>
     646:	e9 31 01 00 00       	jmp    77c <printf+0x19b>
      }
    } else if(state == '%'){
     64b:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
     64f:	0f 85 27 01 00 00    	jne    77c <printf+0x19b>
      if(c == 'd'){
     655:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
     659:	75 2d                	jne    688 <printf+0xa7>
        printint(fd, *ap, 10, 1);
     65b:	8b 45 e8             	mov    -0x18(%ebp),%eax
     65e:	8b 00                	mov    (%eax),%eax
     660:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
     667:	00 
     668:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
     66f:	00 
     670:	89 44 24 04          	mov    %eax,0x4(%esp)
     674:	8b 45 08             	mov    0x8(%ebp),%eax
     677:	89 04 24             	mov    %eax,(%esp)
     67a:	e8 ad fe ff ff       	call   52c <printint>
        ap++;
     67f:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     683:	e9 ed 00 00 00       	jmp    775 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
     688:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
     68c:	74 06                	je     694 <printf+0xb3>
     68e:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
     692:	75 2d                	jne    6c1 <printf+0xe0>
        printint(fd, *ap, 16, 0);
     694:	8b 45 e8             	mov    -0x18(%ebp),%eax
     697:	8b 00                	mov    (%eax),%eax
     699:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
     6a0:	00 
     6a1:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
     6a8:	00 
     6a9:	89 44 24 04          	mov    %eax,0x4(%esp)
     6ad:	8b 45 08             	mov    0x8(%ebp),%eax
     6b0:	89 04 24             	mov    %eax,(%esp)
     6b3:	e8 74 fe ff ff       	call   52c <printint>
        ap++;
     6b8:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     6bc:	e9 b4 00 00 00       	jmp    775 <printf+0x194>
      } else if(c == 's'){
     6c1:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
     6c5:	75 46                	jne    70d <printf+0x12c>
        s = (char*)*ap;
     6c7:	8b 45 e8             	mov    -0x18(%ebp),%eax
     6ca:	8b 00                	mov    (%eax),%eax
     6cc:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
     6cf:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
     6d3:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     6d7:	75 27                	jne    700 <printf+0x11f>
          s = "(null)";
     6d9:	c7 45 f4 6b 10 00 00 	movl   $0x106b,-0xc(%ebp)
        while(*s != 0){
     6e0:	eb 1e                	jmp    700 <printf+0x11f>
          putc(fd, *s);
     6e2:	8b 45 f4             	mov    -0xc(%ebp),%eax
     6e5:	0f b6 00             	movzbl (%eax),%eax
     6e8:	0f be c0             	movsbl %al,%eax
     6eb:	89 44 24 04          	mov    %eax,0x4(%esp)
     6ef:	8b 45 08             	mov    0x8(%ebp),%eax
     6f2:	89 04 24             	mov    %eax,(%esp)
     6f5:	e8 0a fe ff ff       	call   504 <putc>
          s++;
     6fa:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     6fe:	eb 01                	jmp    701 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
     700:	90                   	nop
     701:	8b 45 f4             	mov    -0xc(%ebp),%eax
     704:	0f b6 00             	movzbl (%eax),%eax
     707:	84 c0                	test   %al,%al
     709:	75 d7                	jne    6e2 <printf+0x101>
     70b:	eb 68                	jmp    775 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
     70d:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
     711:	75 1d                	jne    730 <printf+0x14f>
        putc(fd, *ap);
     713:	8b 45 e8             	mov    -0x18(%ebp),%eax
     716:	8b 00                	mov    (%eax),%eax
     718:	0f be c0             	movsbl %al,%eax
     71b:	89 44 24 04          	mov    %eax,0x4(%esp)
     71f:	8b 45 08             	mov    0x8(%ebp),%eax
     722:	89 04 24             	mov    %eax,(%esp)
     725:	e8 da fd ff ff       	call   504 <putc>
        ap++;
     72a:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     72e:	eb 45                	jmp    775 <printf+0x194>
      } else if(c == '%'){
     730:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     734:	75 17                	jne    74d <printf+0x16c>
        putc(fd, c);
     736:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     739:	0f be c0             	movsbl %al,%eax
     73c:	89 44 24 04          	mov    %eax,0x4(%esp)
     740:	8b 45 08             	mov    0x8(%ebp),%eax
     743:	89 04 24             	mov    %eax,(%esp)
     746:	e8 b9 fd ff ff       	call   504 <putc>
     74b:	eb 28                	jmp    775 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
     74d:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
     754:	00 
     755:	8b 45 08             	mov    0x8(%ebp),%eax
     758:	89 04 24             	mov    %eax,(%esp)
     75b:	e8 a4 fd ff ff       	call   504 <putc>
        putc(fd, c);
     760:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     763:	0f be c0             	movsbl %al,%eax
     766:	89 44 24 04          	mov    %eax,0x4(%esp)
     76a:	8b 45 08             	mov    0x8(%ebp),%eax
     76d:	89 04 24             	mov    %eax,(%esp)
     770:	e8 8f fd ff ff       	call   504 <putc>
      }
      state = 0;
     775:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
     77c:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
     780:	8b 55 0c             	mov    0xc(%ebp),%edx
     783:	8b 45 f0             	mov    -0x10(%ebp),%eax
     786:	01 d0                	add    %edx,%eax
     788:	0f b6 00             	movzbl (%eax),%eax
     78b:	84 c0                	test   %al,%al
     78d:	0f 85 70 fe ff ff    	jne    603 <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
     793:	c9                   	leave  
     794:	c3                   	ret    
     795:	66 90                	xchg   %ax,%ax
     797:	90                   	nop

00000798 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
     798:	55                   	push   %ebp
     799:	89 e5                	mov    %esp,%ebp
     79b:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
     79e:	8b 45 08             	mov    0x8(%ebp),%eax
     7a1:	83 e8 08             	sub    $0x8,%eax
     7a4:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     7a7:	a1 08 15 00 00       	mov    0x1508,%eax
     7ac:	89 45 fc             	mov    %eax,-0x4(%ebp)
     7af:	eb 24                	jmp    7d5 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
     7b1:	8b 45 fc             	mov    -0x4(%ebp),%eax
     7b4:	8b 00                	mov    (%eax),%eax
     7b6:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     7b9:	77 12                	ja     7cd <free+0x35>
     7bb:	8b 45 f8             	mov    -0x8(%ebp),%eax
     7be:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     7c1:	77 24                	ja     7e7 <free+0x4f>
     7c3:	8b 45 fc             	mov    -0x4(%ebp),%eax
     7c6:	8b 00                	mov    (%eax),%eax
     7c8:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     7cb:	77 1a                	ja     7e7 <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     7cd:	8b 45 fc             	mov    -0x4(%ebp),%eax
     7d0:	8b 00                	mov    (%eax),%eax
     7d2:	89 45 fc             	mov    %eax,-0x4(%ebp)
     7d5:	8b 45 f8             	mov    -0x8(%ebp),%eax
     7d8:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     7db:	76 d4                	jbe    7b1 <free+0x19>
     7dd:	8b 45 fc             	mov    -0x4(%ebp),%eax
     7e0:	8b 00                	mov    (%eax),%eax
     7e2:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     7e5:	76 ca                	jbe    7b1 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
     7e7:	8b 45 f8             	mov    -0x8(%ebp),%eax
     7ea:	8b 40 04             	mov    0x4(%eax),%eax
     7ed:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     7f4:	8b 45 f8             	mov    -0x8(%ebp),%eax
     7f7:	01 c2                	add    %eax,%edx
     7f9:	8b 45 fc             	mov    -0x4(%ebp),%eax
     7fc:	8b 00                	mov    (%eax),%eax
     7fe:	39 c2                	cmp    %eax,%edx
     800:	75 24                	jne    826 <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
     802:	8b 45 f8             	mov    -0x8(%ebp),%eax
     805:	8b 50 04             	mov    0x4(%eax),%edx
     808:	8b 45 fc             	mov    -0x4(%ebp),%eax
     80b:	8b 00                	mov    (%eax),%eax
     80d:	8b 40 04             	mov    0x4(%eax),%eax
     810:	01 c2                	add    %eax,%edx
     812:	8b 45 f8             	mov    -0x8(%ebp),%eax
     815:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
     818:	8b 45 fc             	mov    -0x4(%ebp),%eax
     81b:	8b 00                	mov    (%eax),%eax
     81d:	8b 10                	mov    (%eax),%edx
     81f:	8b 45 f8             	mov    -0x8(%ebp),%eax
     822:	89 10                	mov    %edx,(%eax)
     824:	eb 0a                	jmp    830 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
     826:	8b 45 fc             	mov    -0x4(%ebp),%eax
     829:	8b 10                	mov    (%eax),%edx
     82b:	8b 45 f8             	mov    -0x8(%ebp),%eax
     82e:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
     830:	8b 45 fc             	mov    -0x4(%ebp),%eax
     833:	8b 40 04             	mov    0x4(%eax),%eax
     836:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     83d:	8b 45 fc             	mov    -0x4(%ebp),%eax
     840:	01 d0                	add    %edx,%eax
     842:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     845:	75 20                	jne    867 <free+0xcf>
    p->s.size += bp->s.size;
     847:	8b 45 fc             	mov    -0x4(%ebp),%eax
     84a:	8b 50 04             	mov    0x4(%eax),%edx
     84d:	8b 45 f8             	mov    -0x8(%ebp),%eax
     850:	8b 40 04             	mov    0x4(%eax),%eax
     853:	01 c2                	add    %eax,%edx
     855:	8b 45 fc             	mov    -0x4(%ebp),%eax
     858:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
     85b:	8b 45 f8             	mov    -0x8(%ebp),%eax
     85e:	8b 10                	mov    (%eax),%edx
     860:	8b 45 fc             	mov    -0x4(%ebp),%eax
     863:	89 10                	mov    %edx,(%eax)
     865:	eb 08                	jmp    86f <free+0xd7>
  } else
    p->s.ptr = bp;
     867:	8b 45 fc             	mov    -0x4(%ebp),%eax
     86a:	8b 55 f8             	mov    -0x8(%ebp),%edx
     86d:	89 10                	mov    %edx,(%eax)
  freep = p;
     86f:	8b 45 fc             	mov    -0x4(%ebp),%eax
     872:	a3 08 15 00 00       	mov    %eax,0x1508
}
     877:	c9                   	leave  
     878:	c3                   	ret    

00000879 <morecore>:

static Header*
morecore(uint nu)
{
     879:	55                   	push   %ebp
     87a:	89 e5                	mov    %esp,%ebp
     87c:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
     87f:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
     886:	77 07                	ja     88f <morecore+0x16>
    nu = 4096;
     888:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
     88f:	8b 45 08             	mov    0x8(%ebp),%eax
     892:	c1 e0 03             	shl    $0x3,%eax
     895:	89 04 24             	mov    %eax,(%esp)
     898:	e8 2f fc ff ff       	call   4cc <sbrk>
     89d:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
     8a0:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
     8a4:	75 07                	jne    8ad <morecore+0x34>
    return 0;
     8a6:	b8 00 00 00 00       	mov    $0x0,%eax
     8ab:	eb 22                	jmp    8cf <morecore+0x56>
  hp = (Header*)p;
     8ad:	8b 45 f4             	mov    -0xc(%ebp),%eax
     8b0:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
     8b3:	8b 45 f0             	mov    -0x10(%ebp),%eax
     8b6:	8b 55 08             	mov    0x8(%ebp),%edx
     8b9:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
     8bc:	8b 45 f0             	mov    -0x10(%ebp),%eax
     8bf:	83 c0 08             	add    $0x8,%eax
     8c2:	89 04 24             	mov    %eax,(%esp)
     8c5:	e8 ce fe ff ff       	call   798 <free>
  return freep;
     8ca:	a1 08 15 00 00       	mov    0x1508,%eax
}
     8cf:	c9                   	leave  
     8d0:	c3                   	ret    

000008d1 <malloc>:

void*
malloc(uint nbytes)
{
     8d1:	55                   	push   %ebp
     8d2:	89 e5                	mov    %esp,%ebp
     8d4:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
     8d7:	8b 45 08             	mov    0x8(%ebp),%eax
     8da:	83 c0 07             	add    $0x7,%eax
     8dd:	c1 e8 03             	shr    $0x3,%eax
     8e0:	83 c0 01             	add    $0x1,%eax
     8e3:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
     8e6:	a1 08 15 00 00       	mov    0x1508,%eax
     8eb:	89 45 f0             	mov    %eax,-0x10(%ebp)
     8ee:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     8f2:	75 23                	jne    917 <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
     8f4:	c7 45 f0 00 15 00 00 	movl   $0x1500,-0x10(%ebp)
     8fb:	8b 45 f0             	mov    -0x10(%ebp),%eax
     8fe:	a3 08 15 00 00       	mov    %eax,0x1508
     903:	a1 08 15 00 00       	mov    0x1508,%eax
     908:	a3 00 15 00 00       	mov    %eax,0x1500
    base.s.size = 0;
     90d:	c7 05 04 15 00 00 00 	movl   $0x0,0x1504
     914:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     917:	8b 45 f0             	mov    -0x10(%ebp),%eax
     91a:	8b 00                	mov    (%eax),%eax
     91c:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
     91f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     922:	8b 40 04             	mov    0x4(%eax),%eax
     925:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     928:	72 4d                	jb     977 <malloc+0xa6>
      if(p->s.size == nunits)
     92a:	8b 45 f4             	mov    -0xc(%ebp),%eax
     92d:	8b 40 04             	mov    0x4(%eax),%eax
     930:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     933:	75 0c                	jne    941 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
     935:	8b 45 f4             	mov    -0xc(%ebp),%eax
     938:	8b 10                	mov    (%eax),%edx
     93a:	8b 45 f0             	mov    -0x10(%ebp),%eax
     93d:	89 10                	mov    %edx,(%eax)
     93f:	eb 26                	jmp    967 <malloc+0x96>
      else {
        p->s.size -= nunits;
     941:	8b 45 f4             	mov    -0xc(%ebp),%eax
     944:	8b 40 04             	mov    0x4(%eax),%eax
     947:	89 c2                	mov    %eax,%edx
     949:	2b 55 ec             	sub    -0x14(%ebp),%edx
     94c:	8b 45 f4             	mov    -0xc(%ebp),%eax
     94f:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
     952:	8b 45 f4             	mov    -0xc(%ebp),%eax
     955:	8b 40 04             	mov    0x4(%eax),%eax
     958:	c1 e0 03             	shl    $0x3,%eax
     95b:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
     95e:	8b 45 f4             	mov    -0xc(%ebp),%eax
     961:	8b 55 ec             	mov    -0x14(%ebp),%edx
     964:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
     967:	8b 45 f0             	mov    -0x10(%ebp),%eax
     96a:	a3 08 15 00 00       	mov    %eax,0x1508
      return (void*)(p + 1);
     96f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     972:	83 c0 08             	add    $0x8,%eax
     975:	eb 38                	jmp    9af <malloc+0xde>
    }
    if(p == freep)
     977:	a1 08 15 00 00       	mov    0x1508,%eax
     97c:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     97f:	75 1b                	jne    99c <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
     981:	8b 45 ec             	mov    -0x14(%ebp),%eax
     984:	89 04 24             	mov    %eax,(%esp)
     987:	e8 ed fe ff ff       	call   879 <morecore>
     98c:	89 45 f4             	mov    %eax,-0xc(%ebp)
     98f:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     993:	75 07                	jne    99c <malloc+0xcb>
        return 0;
     995:	b8 00 00 00 00       	mov    $0x0,%eax
     99a:	eb 13                	jmp    9af <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     99c:	8b 45 f4             	mov    -0xc(%ebp),%eax
     99f:	89 45 f0             	mov    %eax,-0x10(%ebp)
     9a2:	8b 45 f4             	mov    -0xc(%ebp),%eax
     9a5:	8b 00                	mov    (%eax),%eax
     9a7:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
     9aa:	e9 70 ff ff ff       	jmp    91f <malloc+0x4e>
}
     9af:	c9                   	leave  
     9b0:	c3                   	ret    
     9b1:	66 90                	xchg   %ax,%ax
     9b3:	90                   	nop

000009b4 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
     9b4:	55                   	push   %ebp
     9b5:	89 e5                	mov    %esp,%ebp
     9b7:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
     9ba:	c7 05 20 17 00 00 00 	movl   $0x0,0x1720
     9c1:	00 00 00 
	STORE_ESP(ttable[0].esp);
     9c4:	89 e0                	mov    %esp,%eax
     9c6:	a3 24 17 00 00       	mov    %eax,0x1724
	STORE_EBP(ttable[0].ebp);
     9cb:	89 e8                	mov    %ebp,%eax
     9cd:	a3 28 17 00 00       	mov    %eax,0x1728
	ttable[0].state = T_RUNNING;
     9d2:	c7 05 30 17 00 00 01 	movl   $0x1,0x1730
     9d9:	00 00 00 
	ttable[0].wait_num = 0;
     9dc:	c7 05 34 18 00 00 00 	movl   $0x0,0x1834
     9e3:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     9e6:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     9ed:	eb 2c                	jmp    a1b <uthread_init+0x67>
	{
		ttable[i].tid = i;
     9ef:	8b 45 f4             	mov    -0xc(%ebp),%eax
     9f2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     9f8:	8d 90 20 17 00 00    	lea    0x1720(%eax),%edx
     9fe:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a01:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
     a03:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a06:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     a0c:	05 30 17 00 00       	add    $0x1730,%eax
     a11:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     a17:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     a1b:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     a1f:	7e ce                	jle    9ef <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
     a21:	c7 44 24 04 a7 0c 00 	movl   $0xca7,0x4(%esp)
     a28:	00 
     a29:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
     a30:	e8 af fa ff ff       	call   4e4 <signal>
	alarm(THREAD_QUANTA);
     a35:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     a3c:	e8 b3 fa ff ff       	call   4f4 <alarm>
}
     a41:	c9                   	leave  
     a42:	c3                   	ret    

00000a43 <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
     a43:	55                   	push   %ebp
     a44:	89 e5                	mov    %esp,%ebp
     a46:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
     a49:	60                   	pusha  
	ticks = getTicks();
     a4a:	e8 ad fa ff ff       	call   4fc <getTicks>
     a4f:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
     a52:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     a59:	e8 96 fa ff ff       	call   4f4 <alarm>
	asm("popa");
     a5e:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
     a5f:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     a66:	e9 02 01 00 00       	jmp    b6d <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
     a6b:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a6e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     a74:	05 30 17 00 00       	add    $0x1730,%eax
     a79:	8b 00                	mov    (%eax),%eax
     a7b:	85 c0                	test   %eax,%eax
     a7d:	0f 85 e6 00 00 00    	jne    b69 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
     a83:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
     a8a:	e8 42 fe ff ff       	call   8d1 <malloc>
     a8f:	8b 55 f4             	mov    -0xc(%ebp),%edx
     a92:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     a98:	81 c2 20 17 00 00    	add    $0x1720,%edx
     a9e:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
     aa1:	8b 45 f4             	mov    -0xc(%ebp),%eax
     aa4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     aaa:	05 20 17 00 00       	add    $0x1720,%eax
     aaf:	8b 40 0c             	mov    0xc(%eax),%eax
     ab2:	05 00 10 00 00       	add    $0x1000,%eax
     ab7:	89 c4                	mov    %eax,%esp
			PUSH(arg);
     ab9:	8b 45 0c             	mov    0xc(%ebp),%eax
     abc:	89 c7                	mov    %eax,%edi
     abe:	57                   	push   %edi
			PUSH(uthread_exit);
     abf:	b8 2d 0d 00 00       	mov    $0xd2d,%eax
     ac4:	89 c7                	mov    %eax,%edi
     ac6:	57                   	push   %edi
			PUSH(start_func);
     ac7:	8b 45 08             	mov    0x8(%ebp),%eax
     aca:	89 c7                	mov    %eax,%edi
     acc:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
     acd:	b8 00 00 00 00       	mov    $0x0,%eax
     ad2:	89 c7                	mov    %eax,%edi
     ad4:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
     ad5:	89 e0                	mov    %esp,%eax
     ad7:	8b 55 f4             	mov    -0xc(%ebp),%edx
     ada:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     ae0:	81 c2 20 17 00 00    	add    $0x1720,%edx
     ae6:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
     ae9:	8b 45 f4             	mov    -0xc(%ebp),%eax
     aec:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     af2:	05 20 17 00 00       	add    $0x1720,%eax
     af7:	8b 40 08             	mov    0x8(%eax),%eax
     afa:	8b 55 f4             	mov    -0xc(%ebp),%edx
     afd:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     b03:	81 c2 20 17 00 00    	add    $0x1720,%edx
     b09:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
     b0c:	a1 0c 15 00 00       	mov    0x150c,%eax
     b11:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b17:	05 20 17 00 00       	add    $0x1720,%eax
     b1c:	8b 40 04             	mov    0x4(%eax),%eax
     b1f:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
     b21:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b24:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b2a:	05 30 17 00 00       	add    $0x1730,%eax
     b2f:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
     b35:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b38:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b3e:	05 30 18 00 00       	add    $0x1830,%eax
     b43:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
     b4a:	60                   	pusha  
			alarm(ticks);
     b4b:	8b 45 f0             	mov    -0x10(%ebp),%eax
     b4e:	89 04 24             	mov    %eax,(%esp)
     b51:	e8 9e f9 ff ff       	call   4f4 <alarm>
			asm("popa");
     b56:	61                   	popa   
			return ttable[i].tid;
     b57:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b5a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b60:	05 20 17 00 00       	add    $0x1720,%eax
     b65:	8b 00                	mov    (%eax),%eax
     b67:	eb 1e                	jmp    b87 <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
     b69:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     b6d:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     b71:	0f 8e f4 fe ff ff    	jle    a6b <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
     b77:	8b 45 f0             	mov    -0x10(%ebp),%eax
     b7a:	89 04 24             	mov    %eax,(%esp)
     b7d:	e8 72 f9 ff ff       	call   4f4 <alarm>
	//failed - no free thread to use
	return -1;
     b82:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     b87:	c9                   	leave  
     b88:	c3                   	ret    

00000b89 <safe_exit>:

// task 2.4


void safe_exit()
{
     b89:	55                   	push   %ebp
     b8a:	89 e5                	mov    %esp,%ebp
     b8c:	83 ec 28             	sub    $0x28,%esp
     b8f:	eb 01                	jmp    b92 <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
     b91:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     b92:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     b99:	eb 25                	jmp    bc0 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
     b9b:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b9e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ba4:	05 30 17 00 00       	add    $0x1730,%eax
     ba9:	8b 00                	mov    (%eax),%eax
     bab:	85 c0                	test   %eax,%eax
     bad:	74 0d                	je     bbc <safe_exit+0x33>
				uthread_join(tid);
     baf:	8b 45 f4             	mov    -0xc(%ebp),%eax
     bb2:	89 04 24             	mov    %eax,(%esp)
     bb5:	e8 1d 02 00 00       	call   dd7 <uthread_join>
				break;
     bba:	eb 0a                	jmp    bc6 <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     bbc:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     bc0:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     bc4:	7e d5                	jle    b9b <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
     bc6:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
     bca:	75 c5                	jne    b91 <safe_exit+0x8>
			exit();
     bcc:	e8 73 f8 ff ff       	call   444 <exit>

00000bd1 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
     bd1:	55                   	push   %ebp
     bd2:	89 e5                	mov    %esp,%ebp
     bd4:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
     bd7:	a1 0c 15 00 00       	mov    0x150c,%eax
     bdc:	8d 50 01             	lea    0x1(%eax),%edx
     bdf:	89 d0                	mov    %edx,%eax
     be1:	c1 f8 1f             	sar    $0x1f,%eax
     be4:	c1 e8 1a             	shr    $0x1a,%eax
     be7:	01 c2                	add    %eax,%edx
     be9:	83 e2 3f             	and    $0x3f,%edx
     bec:	89 d1                	mov    %edx,%ecx
     bee:	29 c1                	sub    %eax,%ecx
     bf0:	89 c8                	mov    %ecx,%eax
     bf2:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     bf5:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     bfc:	eb 20                	jmp    c1e <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
     bfe:	8b 45 f0             	mov    -0x10(%ebp),%eax
     c01:	8d 50 01             	lea    0x1(%eax),%edx
     c04:	89 d0                	mov    %edx,%eax
     c06:	c1 f8 1f             	sar    $0x1f,%eax
     c09:	c1 e8 1a             	shr    $0x1a,%eax
     c0c:	01 c2                	add    %eax,%edx
     c0e:	83 e2 3f             	and    $0x3f,%edx
     c11:	89 d1                	mov    %edx,%ecx
     c13:	29 c1                	sub    %eax,%ecx
     c15:	89 c8                	mov    %ecx,%eax
     c17:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     c1a:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     c1e:	8b 45 f0             	mov    -0x10(%ebp),%eax
     c21:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c27:	05 30 17 00 00       	add    $0x1730,%eax
     c2c:	8b 00                	mov    (%eax),%eax
     c2e:	83 f8 02             	cmp    $0x2,%eax
     c31:	74 06                	je     c39 <uthread_switch+0x68>
     c33:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     c37:	7e c5                	jle    bfe <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
     c39:	8b 15 0c 15 00 00    	mov    0x150c,%edx
     c3f:	89 e0                	mov    %esp,%eax
     c41:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c47:	81 c2 20 17 00 00    	add    $0x1720,%edx
     c4d:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
     c50:	8b 15 0c 15 00 00    	mov    0x150c,%edx
     c56:	89 e8                	mov    %ebp,%eax
     c58:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c5e:	81 c2 20 17 00 00    	add    $0x1720,%edx
     c64:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
     c67:	8b 45 f0             	mov    -0x10(%ebp),%eax
     c6a:	a3 0c 15 00 00       	mov    %eax,0x150c
	LOAD_EBP(ttable[c_thread].ebp);
     c6f:	a1 0c 15 00 00       	mov    0x150c,%eax
     c74:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c7a:	05 20 17 00 00       	add    $0x1720,%eax
     c7f:	8b 40 08             	mov    0x8(%eax),%eax
     c82:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
     c84:	a1 0c 15 00 00       	mov    0x150c,%eax
     c89:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c8f:	05 20 17 00 00       	add    $0x1720,%eax
     c94:	8b 40 04             	mov    0x4(%eax),%eax
     c97:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
     c99:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     ca0:	e8 4f f8 ff ff       	call   4f4 <alarm>
}
     ca5:	c9                   	leave  
     ca6:	c3                   	ret    

00000ca7 <uthread_yield>:

void uthread_yield()
{
     ca7:	55                   	push   %ebp
     ca8:	89 e5                	mov    %esp,%ebp
     caa:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
     cad:	60                   	pusha  
	alarm(0);
     cae:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     cb5:	e8 3a f8 ff ff       	call   4f4 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
     cba:	a1 0c 15 00 00       	mov    0x150c,%eax
     cbf:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     cc5:	05 30 17 00 00       	add    $0x1730,%eax
     cca:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
     cd0:	e8 fc fe ff ff       	call   bd1 <uthread_switch>
	asm("popa");
     cd5:	61                   	popa   
}
     cd6:	c9                   	leave  
     cd7:	c3                   	ret    

00000cd8 <uthread_awake>:

// task 2.5

void uthread_awake()
{
     cd8:	55                   	push   %ebp
     cd9:	89 e5                	mov    %esp,%ebp
     cdb:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     cde:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     ce5:	eb 2c                	jmp    d13 <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
     ce7:	a1 0c 15 00 00       	mov    0x150c,%eax
     cec:	6b d0 46             	imul   $0x46,%eax,%edx
     cef:	8b 45 fc             	mov    -0x4(%ebp),%eax
     cf2:	01 d0                	add    %edx,%eax
     cf4:	83 c0 04             	add    $0x4,%eax
     cf7:	8b 04 85 24 17 00 00 	mov    0x1724(,%eax,4),%eax
     cfe:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d04:	05 30 17 00 00       	add    $0x1730,%eax
     d09:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     d0f:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     d13:	a1 0c 15 00 00       	mov    0x150c,%eax
     d18:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d1e:	05 30 18 00 00       	add    $0x1830,%eax
     d23:	8b 40 04             	mov    0x4(%eax),%eax
     d26:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     d29:	7f bc                	jg     ce7 <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
     d2b:	c9                   	leave  
     d2c:	c3                   	ret    

00000d2d <uthread_exit>:

void uthread_exit()
{
     d2d:	55                   	push   %ebp
     d2e:	89 e5                	mov    %esp,%ebp
     d30:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     d33:	60                   	pusha  
	alarm(0);
     d34:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     d3b:	e8 b4 f7 ff ff       	call   4f4 <alarm>
	asm("popa");
     d40:	61                   	popa   
	ttable[c_thread].state = T_FREE;
     d41:	a1 0c 15 00 00       	mov    0x150c,%eax
     d46:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d4c:	05 30 17 00 00       	add    $0x1730,%eax
     d51:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
     d57:	a1 0c 15 00 00       	mov    0x150c,%eax
     d5c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d62:	05 20 17 00 00       	add    $0x1720,%eax
     d67:	8b 00                	mov    (%eax),%eax
     d69:	85 c0                	test   %eax,%eax
     d6b:	74 1d                	je     d8a <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
     d6d:	a1 0c 15 00 00       	mov    0x150c,%eax
     d72:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d78:	05 20 17 00 00       	add    $0x1720,%eax
     d7d:	8b 40 0c             	mov    0xc(%eax),%eax
     d80:	89 04 24             	mov    %eax,(%esp)
     d83:	e8 10 fa ff ff       	call   798 <free>
     d88:	eb 05                	jmp    d8f <uthread_exit+0x62>
	else
		safe_exit();
     d8a:	e8 fa fd ff ff       	call   b89 <safe_exit>
	uthread_awake();
     d8f:	e8 44 ff ff ff       	call   cd8 <uthread_awake>
	uthread_switch();
     d94:	e8 38 fe ff ff       	call   bd1 <uthread_switch>
	asm("popa");
     d99:	61                   	popa   
}
     d9a:	c9                   	leave  
     d9b:	c3                   	ret    

00000d9c <uthread_self>:

// task 2.6

int uthread_self()
{
     d9c:	55                   	push   %ebp
     d9d:	89 e5                	mov    %esp,%ebp
	return c_thread;
     d9f:	a1 0c 15 00 00       	mov    0x150c,%eax
}
     da4:	5d                   	pop    %ebp
     da5:	c3                   	ret    

00000da6 <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
     da6:	55                   	push   %ebp
     da7:	89 e5                	mov    %esp,%ebp
     da9:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     dac:	60                   	pusha  
	alarm(0);
     dad:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     db4:	e8 3b f7 ff ff       	call   4f4 <alarm>
	ttable[c_thread].state = T_SLEEPING;
     db9:	a1 0c 15 00 00       	mov    0x150c,%eax
     dbe:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     dc4:	05 30 17 00 00       	add    $0x1730,%eax
     dc9:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
     dcf:	e8 fd fd ff ff       	call   bd1 <uthread_switch>
	asm("popa");
     dd4:	61                   	popa   
}
     dd5:	c9                   	leave  
     dd6:	c3                   	ret    

00000dd7 <uthread_join>:

int uthread_join(int tid)
{
     dd7:	55                   	push   %ebp
     dd8:	89 e5                	mov    %esp,%ebp
     dda:	53                   	push   %ebx
     ddb:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
     dde:	60                   	pusha  
	ticks = getTicks();
     ddf:	e8 18 f7 ff ff       	call   4fc <getTicks>
     de4:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
     de7:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     dee:	e8 01 f7 ff ff       	call   4f4 <alarm>
	asm("popa");
     df3:	61                   	popa   
	if (ttable[tid].state != T_FREE)
     df4:	8b 45 08             	mov    0x8(%ebp),%eax
     df7:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     dfd:	05 30 17 00 00       	add    $0x1730,%eax
     e02:	8b 00                	mov    (%eax),%eax
     e04:	85 c0                	test   %eax,%eax
     e06:	74 5e                	je     e66 <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
     e08:	8b 45 08             	mov    0x8(%ebp),%eax
     e0b:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e11:	05 10 01 00 00       	add    $0x110,%eax
     e16:	05 20 17 00 00       	add    $0x1720,%eax
     e1b:	8d 48 04             	lea    0x4(%eax),%ecx
     e1e:	8b 45 08             	mov    0x8(%ebp),%eax
     e21:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e27:	05 30 18 00 00       	add    $0x1830,%eax
     e2c:	8b 40 04             	mov    0x4(%eax),%eax
     e2f:	8b 15 0c 15 00 00    	mov    0x150c,%edx
     e35:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     e3b:	81 c2 20 17 00 00    	add    $0x1720,%edx
     e41:	8b 12                	mov    (%edx),%edx
     e43:	8b 5d 08             	mov    0x8(%ebp),%ebx
     e46:	6b db 46             	imul   $0x46,%ebx,%ebx
     e49:	01 c3                	add    %eax,%ebx
     e4b:	83 c3 04             	add    $0x4,%ebx
     e4e:	89 14 9d 24 17 00 00 	mov    %edx,0x1724(,%ebx,4)
     e55:	83 c0 01             	add    $0x1,%eax
     e58:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
     e5a:	e8 47 ff ff ff       	call   da6 <uthread_sleep>
		return 0;
     e5f:	b8 00 00 00 00       	mov    $0x0,%eax
     e64:	eb 12                	jmp    e78 <uthread_join+0xa1>
	}
	asm("pusha");
     e66:	60                   	pusha  
	alarm(ticks);
     e67:	8b 45 f4             	mov    -0xc(%ebp),%eax
     e6a:	89 04 24             	mov    %eax,(%esp)
     e6d:	e8 82 f6 ff ff       	call   4f4 <alarm>
	asm("popa");
     e72:	61                   	popa   
	return -1;
     e73:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     e78:	83 c4 24             	add    $0x24,%esp
     e7b:	5b                   	pop    %ebx
     e7c:	5d                   	pop    %ebp
     e7d:	c3                   	ret    

00000e7e <queue_init>:

void queue_init(struct tqueue *q)
{
     e7e:	55                   	push   %ebp
     e7f:	89 e5                	mov    %esp,%ebp
	q->head = 0;
     e81:	8b 45 08             	mov    0x8(%ebp),%eax
     e84:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
     e8b:	00 00 00 
	q->tail = 0;
     e8e:	8b 45 08             	mov    0x8(%ebp),%eax
     e91:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
     e98:	00 00 00 
}
     e9b:	5d                   	pop    %ebp
     e9c:	c3                   	ret    

00000e9d <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
     e9d:	55                   	push   %ebp
     e9e:	89 e5                	mov    %esp,%ebp
     ea0:	57                   	push   %edi
     ea1:	56                   	push   %esi
     ea2:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
     ea3:	8b 45 08             	mov    0x8(%ebp),%eax
     ea6:	8b 00                	mov    (%eax),%eax
     ea8:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
     eae:	8b 45 08             	mov    0x8(%ebp),%eax
     eb1:	8b 00                	mov    (%eax),%eax
     eb3:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
     eb9:	39 c2                	cmp    %eax,%edx
     ebb:	75 07                	jne    ec4 <dequeue+0x27>
		return 0;
     ebd:	b9 00 00 00 00       	mov    $0x0,%ecx
     ec2:	eb 31                	jmp    ef5 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
     ec4:	8b 45 08             	mov    0x8(%ebp),%eax
     ec7:	8b 18                	mov    (%eax),%ebx
     ec9:	8b 45 08             	mov    0x8(%ebp),%eax
     ecc:	8b 10                	mov    (%eax),%edx
     ece:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
     ed4:	89 c1                	mov    %eax,%ecx
     ed6:	c1 f9 1f             	sar    $0x1f,%ecx
     ed9:	c1 e9 1a             	shr    $0x1a,%ecx
     edc:	8d 34 08             	lea    (%eax,%ecx,1),%esi
     edf:	83 e6 3f             	and    $0x3f,%esi
     ee2:	89 f7                	mov    %esi,%edi
     ee4:	29 cf                	sub    %ecx,%edi
     ee6:	89 f9                	mov    %edi,%ecx
     ee8:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
     eeb:	83 c0 01             	add    $0x1,%eax
     eee:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
     ef4:	90                   	nop
     ef5:	89 c8                	mov    %ecx,%eax
}
     ef7:	5b                   	pop    %ebx
     ef8:	5e                   	pop    %esi
     ef9:	5f                   	pop    %edi
     efa:	5d                   	pop    %ebp
     efb:	c3                   	ret    

00000efc <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
     efc:	55                   	push   %ebp
     efd:	89 e5                	mov    %esp,%ebp
     eff:	57                   	push   %edi
     f00:	56                   	push   %esi
     f01:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
     f02:	8b 45 08             	mov    0x8(%ebp),%eax
     f05:	8b 18                	mov    (%eax),%ebx
     f07:	8b 45 08             	mov    0x8(%ebp),%eax
     f0a:	8b 10                	mov    (%eax),%edx
     f0c:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
     f12:	89 c1                	mov    %eax,%ecx
     f14:	c1 f9 1f             	sar    $0x1f,%ecx
     f17:	c1 e9 1a             	shr    $0x1a,%ecx
     f1a:	8d 34 08             	lea    (%eax,%ecx,1),%esi
     f1d:	83 e6 3f             	and    $0x3f,%esi
     f20:	89 f7                	mov    %esi,%edi
     f22:	29 cf                	sub    %ecx,%edi
     f24:	89 f9                	mov    %edi,%ecx
     f26:	8b 35 0c 15 00 00    	mov    0x150c,%esi
     f2c:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
     f32:	81 c6 20 17 00 00    	add    $0x1720,%esi
     f38:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
     f3b:	83 c0 01             	add    $0x1,%eax
     f3e:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
     f44:	5b                   	pop    %ebx
     f45:	5e                   	pop    %esi
     f46:	5f                   	pop    %edi
     f47:	5d                   	pop    %ebp
     f48:	c3                   	ret    

00000f49 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
     f49:	55                   	push   %ebp
     f4a:	89 e5                	mov    %esp,%ebp
     f4c:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
     f4f:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
     f56:	e8 76 f9 ff ff       	call   8d1 <malloc>
     f5b:	8b 55 08             	mov    0x8(%ebp),%edx
     f5e:	89 02                	mov    %eax,(%edx)
	if (!value)
     f60:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
     f64:	75 0c                	jne    f72 <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
     f66:	8b 45 08             	mov    0x8(%ebp),%eax
     f69:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
     f70:	eb 0a                	jmp    f7c <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
     f72:	8b 45 08             	mov    0x8(%ebp),%eax
     f75:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
     f7c:	c9                   	leave  
     f7d:	c3                   	ret    

00000f7e <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
     f7e:	55                   	push   %ebp
     f7f:	89 e5                	mov    %esp,%ebp
     f81:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
     f84:	60                   	pusha  
	ticks = getTicks();
     f85:	e8 72 f5 ff ff       	call   4fc <getTicks>
     f8a:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
     f8d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f94:	e8 5b f5 ff ff       	call   4f4 <alarm>
	asm("popa");
     f99:	61                   	popa   
	if (semaphore->state == S_LOCKED)
     f9a:	8b 45 08             	mov    0x8(%ebp),%eax
     f9d:	8b 40 04             	mov    0x4(%eax),%eax
     fa0:	83 f8 01             	cmp    $0x1,%eax
     fa3:	75 1c                	jne    fc1 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
     fa5:	8b 45 08             	mov    0x8(%ebp),%eax
     fa8:	89 04 24             	mov    %eax,(%esp)
     fab:	e8 4c ff ff ff       	call   efc <enqueue>
		uthread_sleep();
     fb0:	e8 f1 fd ff ff       	call   da6 <uthread_sleep>
		alarm(0);
     fb5:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     fbc:	e8 33 f5 ff ff       	call   4f4 <alarm>
	}
	semaphore->state = S_LOCKED;
     fc1:	8b 45 08             	mov    0x8(%ebp),%eax
     fc4:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
     fcb:	8b 45 f4             	mov    -0xc(%ebp),%eax
     fce:	89 04 24             	mov    %eax,(%esp)
     fd1:	e8 1e f5 ff ff       	call   4f4 <alarm>

}
     fd6:	c9                   	leave  
     fd7:	c3                   	ret    

00000fd8 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
     fd8:	55                   	push   %ebp
     fd9:	89 e5                	mov    %esp,%ebp
     fdb:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
     fde:	60                   	pusha  
	ticks = getTicks();
     fdf:	e8 18 f5 ff ff       	call   4fc <getTicks>
     fe4:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
     fe7:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     fee:	e8 01 f5 ff ff       	call   4f4 <alarm>
	asm("popa");
     ff3:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
     ff4:	8b 45 08             	mov    0x8(%ebp),%eax
     ff7:	89 04 24             	mov    %eax,(%esp)
     ffa:	e8 9e fe ff ff       	call   e9d <dequeue>
     fff:	89 45 f0             	mov    %eax,-0x10(%ebp)
    1002:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
    1006:	75 19                	jne    1021 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
    1008:	8b 45 08             	mov    0x8(%ebp),%eax
    100b:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
    1012:	60                   	pusha  
		alarm(ticks);
    1013:	8b 45 f4             	mov    -0xc(%ebp),%eax
    1016:	89 04 24             	mov    %eax,(%esp)
    1019:	e8 d6 f4 ff ff       	call   4f4 <alarm>
		asm("popa");
    101e:	61                   	popa   
    101f:	eb 0f                	jmp    1030 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
    1021:	8b 45 f0             	mov    -0x10(%ebp),%eax
    1024:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
    102b:	e8 77 fc ff ff       	call   ca7 <uthread_yield>
	}
}
    1030:	c9                   	leave  
    1031:	c3                   	ret    
